/*本工具是无引用类小功能函数*/
export default {
	get now(){
		return Date.now();
	},
    get time(){
        let zeroNum=n=>n.toString().length<2?`0${n}`:n-0;
        let t=new Date(),
            y=t.getFullYear(),
            m=t.getMonth()+1,
            d=t.getDate(),
            h=zeroNum(t.getHours()),
            i=zeroNum(t.getMinutes()),
            s=zeroNum(t.getSeconds()),
            time=`${y}-${m}-${d} ${h}:${i}:${s}`;
            return time;
    },
	goBack: (navigator)=>{
		if (navigator && navigator.getCurrentRoutes().length > 1) {
		  navigator.pop();
		  return true;
		}
		return false;
	},
	get: (url, successCallback, failCallback) => {
        fetch(url)
            .then((response) => response.text())
            .then((responseText) => {
                successCallback(JSON.parse(responseText));
            })
            .catch((err) => {
                failCallback(err);
            });
    },
    gets: (url, successCallback, failCallback) => {
        var request = new XMLHttpRequest();
        request.onreadystatechange = (e) => {
            if (request.readyState !== 4) {
                return;
            }
            if (request.status === 200) {
                 successCallback(JSON.parse(request.responseText))
            } else {
                // console.warn('error');
            }
        };
        request.open('GET',url);
        request.send();
    },
    //获取obj的type
    //当只有obj时,获取type,当有type时,判断type
    isType:(obj,type)=>{
        return tp=Object.prototype.toString.call(obj).slice(8, -1).toLowerCase(),!type?tp:tp===type.toLowerCase();
    },
}